<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础数据管理-项目信息新增</title>
    <script src="/scripts/boot.js"></script>
</head>
<body class="bg-white">
<div id="viewForm">
    <div class="title-info mb-20"><span>权限节点</span></div>
    <div class="container">
        <div class="mini-clearfix mb-10">
            <div class="mini-col-6 mini-col-sm-3">
                <a class="plan-btn mR-20"  onclick="view.onAddNode()">新增</a>
                <a class="plan-btn mR-20"  onclick="view.onEditNode()">编辑</a>
                <!--<a class="plan-btn mR-20"  onclick="view.onRemoveNode()">删除</a>-->
            </div>
        </div>
    </div>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <!--<input type="button" value="插入节点(子节点)" onclick="view.onAddNode()"/>-->
        <!--<input type="button" value="编辑节点" onclick="view.onEditNode()"/>-->
        <!--<input type="button" value="删除节点" onclick="view.onRemoveNode()"/>-->
        <!--<tr>-->
            <!--<td class="text-titlebg"><span class="color-red">*</span>名称</td>-->
            <!--<td>-->
                <!--&lt;!&ndash; required="true" errorMode="none" onvalidation="onEnglishAndNumberValidation" requiredErrorText="请输入"&ndash;&gt;-->
                <!--<input type="text" name="name" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/>-->
            <!--</td>-->
            <!--<td class="text-titlebg"><span class="color-red">*</span>类型</td>-->
            <!--<td>-->
                <!--<input name="resourceType" class="mini-checkbox w250" text="类型" value="0" trueValue="0" falseValue="1" />-->
                <!--&lt;!&ndash;<input type="text" name="resourceType" value="0" class="mini-textbox w250"/>&ndash;&gt;-->
            <!--</td>-->
        <!--</tr>-->
        <!--<tr>-->
            <!--<td class="text-titlebg">-->
                <!--资源路径-->
                <!--&lt;!&ndash;<span class="color-red">*</span>&ndash;&gt;-->
            <!--</td>-->
            <!--<td>-->
                <!--<input type="text" name="url" class="mini-textbox w250"/>-->
            <!--</td>-->
            <!--<td class="text-titlebg">-->
                <!--权限字符串-->
            <!--</td>-->
            <!--<td>-->
                <!--<input type="text" name="permission" class="mini-textbox w250"/>-->
            <!--</td>-->
        <!--</tr>-->
        <!--<tr>-->
            <!--<td class="text-titlebg">-->
                <!--父编号-->
                <!--&lt;!&ndash;<span class="color-red">*</span>&ndash;&gt;-->
            <!--</td>-->
            <!--<td>-->
                <!--<input type="text" name="pId" class="mini-textbox w250"/>-->
            <!--</td>-->
            <!--<td class="text-titlebg">-->
                <!--是否可用-->
            <!--</td>-->
            <!--<td>-->
                <!--<input name="available" class="mini-checkbox w250" text="是否可用" value="0" trueValue="0" falseValue="1" />-->
                <!--&lt;!&ndash;<input type="text" name="pIds" class="mini-textbox w250"/>&ndash;&gt;-->
            <!--</td>-->
        <!--</tr>-->
        <tr>
            <td colspan="4">
                <!--<input type="button" value="插入节点(前)" onclick="view.onAddBefore()"/>-->
                <!--<input type="button" value="插入节点(后)" onclick="view.onAddAfter()"/>-->

                <ul id="tree1" class="mini-tree" url="/permission/list" style="width:400px;padding:5px; height: 200px;"
                    showTreeIcon="true" textField="name" idField="id"expandOnLoad="true" parentField="pId" resultAsTree="false" allowDrag="true" allowDrop="true" >
                </ul>
            </td>
        </tr>
    </table>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
    </div>
</div>
<script type="text/javascript">
    var post_flag,form,state,datas,chooseNode;
    var view = {
        init: function () {
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.parse();
            form = new mini.Form("#viewForm");
            view.listData();
        },
        listData:function(){
            $.ajax({
                url: "/permission/list",
                type: "post",
                success: function (msg) {
                    chooseNode = msg;
                },
                error: function (errorMsg) {
                    post_flag = false;
                    var msg  = JSON.parse(errorMsg.responseText);
                    common.prompt(msg.message);
                }
            });
        },
        //插入节点(前)
        // onAddBefore:function(){
        //     var tree = mini.get("tree1");
        //     var node = tree.getSelectedNode();
        //
        //     var newNode = {};
        //     tree.addNode(newNode, "before", node);
        // },
        // //插入节点(后)
        // onAddAfter:function(){
        //     var tree = mini.get("tree1");
        //     var node = tree.getSelectedNode();
        //
        //     var newNode = {};
        //     tree.addNode(newNode, "after", node);
        // },
        //插入节点(子节点)
        onAddNode:function(){
            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();
            if(chooseNode.length>0){
                if(node!=undefined){
                    mini.open({
                        url: "/dataBase/authority/authority.html",
                        title: "新增权限信息", width: 1100, height: 500,
                        onload: function () {
                            var data = {"id": node,"state":"new","chooseNode":chooseNode};
                            var iframe = this.getIFrameEl();
                            iframe.contentWindow.view.SetData(data);
                        },
                        ondestroy: function (action) {
                            window.location.reload();
                            self.opener.location.reload();
                        }
                    });
                    // var newNode = {};
                    // tree.addNode(newNode, "add", node);
                }else {
                    mini.alert("请选中一节点");
                }
            }else {
                mini.open({
                    url: "/dataBase/authority/authority.html",
                    title: "新增权限信息", width: 1100, height: 500,
                    onload: function () {
                        var data = {"id": "","state":"new","chooseNode":chooseNode};
                        var iframe = this.getIFrameEl();
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        window.location.reload();
                    }
                });
            }
        },
        //编辑节点
        onEditNode:function(){
            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();
            if(node!=undefined){
                mini.open({
                    url: "/dataBase/authority/authority.html",
                    title: "编辑权限信息", width: 1100, height: 500,
                    onload: function () {
                        var data = {"id": node,"state":"edit","chooseNode":chooseNode};
                        var iframe = this.getIFrameEl();
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        window.location.reload();
                    }
                });
            }else{
                mini.alert("请选中一节点");
            }
            // tree.beginEdit(node);
        },
        //删除节点
        onRemoveNode:function(){
            var tree = mini.get("tree1");
            var node = tree.getSelectedNode();
            if (node) {
                if (mini.confirm("确定删除选中节点?")) {
                    $.ajax({
                        url:"/permission/del?id=" + node.id,
                        type: "post",
                        success: function (text) {

                        },
                        error:function (errorMsg) {
                            var msg  = JSON.parse(errorMsg.responseText);
                            common.prompt(msg.message);
                        }
                    });
                }
            }else{
                mini.alert("请选中一节点");
            }
        }
    };
    view.init();
</script>
</body>
</html>